package com.share.hope.controller;


import com.share.hope.entity.result.R;
import com.share.hope.service.CommonService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@RestController
@RequestMapping("/share/hope/common")
@RequiredArgsConstructor
@Slf4j
@Tag(name = "通用信息管理接口")
@CrossOrigin
public class CommonController {

    private final CommonService commonService;

    @PostMapping("/upload-avatar")
    @Operation(summary = "头像上传")
    public R<String> uploadAvatar(@RequestParam("file") MultipartFile file) throws IOException {
        return commonService.uploadAvatar(file);
    }

    @GetMapping("/view-avatar")
    @Operation(summary = "头像查看")
    public void viewImage(@RequestParam("path") String path, HttpServletResponse response) throws IOException{
        commonService.viewImage(path, response);
    }

    @PostMapping("/amplify")
    @Operation(summary = "图像无损放大")
    public void imgAmplify(@RequestParam("file") MultipartFile file, HttpServletResponse response) throws IOException {
        commonService.imgAmplify(file, response);
    }

    @PostMapping("/anime")
    @Operation(summary = "人像动漫化")
    public void imgAnime(@RequestParam("file") MultipartFile file, HttpServletResponse response) throws IOException {
        commonService.imgAnime(file, response);
    }
}
